﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.Caching;
using System.Web.Mvc;
using WeiSha.Core.Templates;

namespace WeiSha.Core
{
	// Token: 0x0200002C RID: 44
	public class TemplateDocument
	{
		// Token: 0x17000091 RID: 145
		// (get) Token: 0x0600017B RID: 379 RVA: 0x0000A863 File Offset: 0x00008A63
		// (set) Token: 0x0600017C RID: 380 RVA: 0x0000A86B File Offset: 0x00008A6B
		public string Type { get; set; }

		// Token: 0x17000092 RID: 146
		// (get) Token: 0x0600017D RID: 381 RVA: 0x0000A874 File Offset: 0x00008A74
		// (set) Token: 0x0600017E RID: 382 RVA: 0x0000A87C File Offset: 0x00008A7C
		public string Module { get; set; }

		// Token: 0x17000093 RID: 147
		// (get) Token: 0x0600017F RID: 383 RVA: 0x0000A885 File Offset: 0x00008A85
		// (set) Token: 0x06000180 RID: 384 RVA: 0x0000A88D File Offset: 0x00008A8D
		public string FileView { get; set; }

		// Token: 0x17000094 RID: 148
		// (get) Token: 0x06000181 RID: 385 RVA: 0x0000A896 File Offset: 0x00008A96
		// (set) Token: 0x06000182 RID: 386 RVA: 0x0000A89E File Offset: 0x00008A9E
		public string FileName { get; set; }

		// Token: 0x17000095 RID: 149
		// (get) Token: 0x06000183 RID: 387 RVA: 0x0000A8A7 File Offset: 0x00008AA7
		// (set) Token: 0x06000184 RID: 388 RVA: 0x0000A8AF File Offset: 0x00008AAF
		public string FilePath { get; set; }

		// Token: 0x17000096 RID: 150
		// (get) Token: 0x06000185 RID: 389 RVA: 0x0000A8B8 File Offset: 0x00008AB8
		// (set) Token: 0x06000186 RID: 390 RVA: 0x0000A8C0 File Offset: 0x00008AC0
		public string FilePhysic { get; set; }

		// Token: 0x17000097 RID: 151
		// (get) Token: 0x06000187 RID: 391 RVA: 0x0000A8C9 File Offset: 0x00008AC9
		// (set) Token: 0x06000188 RID: 392 RVA: 0x0000A8D1 File Offset: 0x00008AD1
		public string FileVirtual { get; set; }

		// Token: 0x17000098 RID: 152
		// (get) Token: 0x06000189 RID: 393 RVA: 0x0000A8DA File Offset: 0x00008ADA
		// (set) Token: 0x0600018A RID: 394 RVA: 0x0000A8E2 File Offset: 0x00008AE2
		public string AbsolutePath { get; set; }

		// Token: 0x17000099 RID: 153
		// (get) Token: 0x0600018B RID: 395 RVA: 0x0000A8EC File Offset: 0x00008AEC
		public List<string> FileDependencies
		{
			get
			{
				object fileDependencies_lock = TemplateDocument._fileDependencies_lock;
				List<string> fileDependencies;
				lock (fileDependencies_lock)
				{
					bool flag2 = this._fileDependencies == null;
					if (flag2)
					{
						this._fileDependencies = new List<string>();
						this._fileDependencies.Add(Copyright.File);
					}
					fileDependencies = this._fileDependencies;
				}
				return fileDependencies;
			}
		}

		// Token: 0x1700009A RID: 154
		// (get) Token: 0x0600018C RID: 396 RVA: 0x0000A95C File Offset: 0x00008B5C
		// (set) Token: 0x0600018D RID: 397 RVA: 0x0000A964 File Offset: 0x00008B64
		private TemplateBank TemplateBank { get; set; }

		// Token: 0x0600018E RID: 398 RVA: 0x0000A970 File Offset: 0x00008B70
		public TemplateDocument(ViewContext viewContext)
		{
			this.AbsolutePath = viewContext.HttpContext.Request.Url.AbsolutePath;
			string[] array = TemplateDocument.PathItem(viewContext);
			this.TemplateBank = this._init(array);
			bool flag = this.TemplateBank == null;
			if (flag)
			{
				this.FileName = "404";
				this.AbsolutePath = "/" + this.Type + "/" + this.FileName;
				this.FilePath = string.Format("{0}.html", this.FileName);
				this.TemplateBank = this.SetTemplateBank(array[0], this.FilePath);
			}
		}

		// Token: 0x0600018F RID: 399 RVA: 0x0000AA28 File Offset: 0x00008C28
		private TemplateBank _init(string[] item)
		{
			this.Type = item[0];
			this.Module = (string.IsNullOrWhiteSpace(item[2]) ? "" : item[1]);
			this.FileName = (string.IsNullOrWhiteSpace(item[2]) ? item[1] : item[2]);
			this.FileView = this.FileName;
			this.FilePath = (string.IsNullOrWhiteSpace(item[2]) ? string.Format("{0}.html", item[1]) : string.Format("{0}/{1}.html", item[1], item[2]));
			TemplateBank templateBank = this.SetTemplateBank(item[0], this.FilePath);
			bool flag = templateBank == null && item[2] == "";
			if (flag)
			{
				item[2] = (string.IsNullOrWhiteSpace(Template.Homepage) ? "index" : Template.Homepage);
				templateBank = this._init(item);
			}
			return templateBank;
		}

		// Token: 0x06000190 RID: 400 RVA: 0x0000AB04 File Offset: 0x00008D04
		private TemplateBank SetTemplateBank(string device, string filepath)
		{
			TemplateBank templateBank = TemplateEngine.Template(device);
			filepath = filepath.Replace("/", "\\");
			this.AddFileDependency(templateBank.Path.Physics + filepath);
			bool flag = templateBank != null && templateBank.PageExists(filepath);
			TemplateBank templateBank2;
			if (flag)
			{
				this.FileVirtual = templateBank.Path.Virtual + filepath;
				this.FilePhysic = templateBank.Path.Physics + filepath;
				templateBank2 = templateBank;
			}
			else
			{
				templateBank = templateBank.Config.Default;
				this.AddFileDependency(templateBank.Path.Physics + filepath);
				bool flag2 = templateBank.PageExists(filepath);
				if (flag2)
				{
					this.FileVirtual = templateBank.Path.Virtual + filepath;
					this.FilePhysic = templateBank.Path.Physics + filepath;
					templateBank2 = templateBank;
				}
				else
				{
					templateBank = templateBank.Config.Public;
					this.AddFileDependency(templateBank.Path.Physics + filepath);
					bool flag3 = templateBank != null && templateBank.PageExists(filepath);
					if (flag3)
					{
						this.FileVirtual = templateBank.Path.Virtual + filepath;
						this.FilePhysic = templateBank.Path.Physics + filepath;
						templateBank2 = templateBank;
					}
					else
					{
						templateBank2 = null;
					}
				}
			}
			return templateBank2;
		}

		// Token: 0x06000191 RID: 401 RVA: 0x0000AC64 File Offset: 0x00008E64
		public void AddFileDependency(string fileName)
		{
			bool flag = string.IsNullOrWhiteSpace(fileName);
			if (!flag)
			{
				try
				{
					lock (this)
					{
						bool flag3 = this.FileDependencies == null;
						if (!flag3)
						{
							foreach (string text in this.FileDependencies)
							{
								bool flag4 = string.IsNullOrWhiteSpace(text);
								if (!flag4)
								{
									bool flag5 = text.Equals(fileName, StringComparison.InvariantCultureIgnoreCase);
									if (flag5)
									{
										return;
									}
								}
							}
							this.FileDependencies.Add(fileName);
						}
					}
				}
				catch (Exception ex)
				{
					Log.Error(base.GetType().ToString(), ex);
					Log.Error(base.GetType().ToString() + "fileName:", fileName);
				}
			}
		}

		// Token: 0x06000192 RID: 402 RVA: 0x0000AD74 File Offset: 0x00008F74
		public static string CacheKey(ViewContext viewContext)
		{
			string[] array = TemplateDocument.PathItem(viewContext);
			string host = viewContext.RequestContext.HttpContext.Request.Url.Host;
			return string.Format("WEISHAKEJI_TEMPLATE_DOCUMENT_{3}_{0}_{1}_{2}", new object[]
			{
				array[0],
				array[1],
				array[2],
				host
			}).ToUpper();
		}

		// Token: 0x06000193 RID: 403 RVA: 0x0000ADD4 File Offset: 0x00008FD4
		public static string[] PathItem(ViewContext viewContext)
		{
			string text = string.Empty;
			string text2 = string.Empty;
			string text3 = string.Empty;
			foreach (string text4 in viewContext.RouteData.Values.Keys)
			{
				bool flag = text4.Equals("controller", StringComparison.OrdinalIgnoreCase);
				if (flag)
				{
					text = viewContext.RouteData.Values["controller"].ToString();
				}
				bool flag2 = text4.Equals("action", StringComparison.OrdinalIgnoreCase);
				if (flag2)
				{
					text2 = viewContext.RouteData.Values["action"].ToString();
				}
				bool flag3 = text4.Equals("id", StringComparison.OrdinalIgnoreCase);
				if (flag3)
				{
					text3 = viewContext.RouteData.Values["id"].ToString();
				}
			}
			bool flag4 = text2.IndexOf(".") > -1;
			if (flag4)
			{
				text2 = text2.Substring(0, text2.IndexOf("."));
			}
			bool flag5 = text3.IndexOf(".") > -1;
			if (flag5)
			{
				text3 = text3.Substring(0, text3.IndexOf("."));
			}
			return new string[] { text, text2, text3 };
		}

		// Token: 0x06000194 RID: 404 RVA: 0x0000AF38 File Offset: 0x00009138
		public static string FromFileCache(ViewContext viewContext)
		{
			Cache cache = HttpRuntime.Cache;
			bool flag = cache == null;
			string text;
			if (flag)
			{
				text = TemplateDocument.FromFile(viewContext);
			}
			else
			{
				string text2 = TemplateDocument.CacheKey(viewContext);
				object obj = cache.Get(text2);
				bool flag2 = obj != null;
				if (flag2)
				{
					text = (string)obj;
				}
				else
				{
					TemplateDocument templateDocument = new TemplateDocument(viewContext);
					bool flag3 = !File.Exists(templateDocument.FilePhysic);
					if (flag3)
					{
						text = TemplateDocument.FromFile(viewContext);
					}
					else
					{
						string text3 = templateDocument.PageHtml();
						try
						{
							foreach (string text4 in templateDocument.FileDependencies)
							{
								bool flag4 = !File.Exists(text4);
								if (flag4)
								{
									return text3;
								}
							}
							object lock_cache = TemplateDocument._lock_cache;
							lock (lock_cache)
							{
								cache.Insert(text2, text3, new CacheDependency(templateDocument.FileDependencies.ToArray()));
							}
						}
						catch (Exception ex)
						{
							Log.Error("TemplateDocument.FromFileCache", ex);
							throw ex;
						}
						text = text3;
					}
				}
			}
			return text;
		}

		// Token: 0x06000195 RID: 405 RVA: 0x0000B08C File Offset: 0x0000928C
		public static string FromFile(ViewContext viewContext)
		{
			TemplateDocument templateDocument = new TemplateDocument(viewContext);
			bool flag = string.IsNullOrWhiteSpace(templateDocument.FilePhysic) || !File.Exists(templateDocument.FilePhysic);
			string text2;
			if (flag)
			{
				string text = viewContext.HttpContext.Request.Url.AbsolutePath;
				text = string.Format("template page '{0}' does not exist", text.ToLower());
				try
				{
					throw new Exception(text);
				}
				catch (Exception ex)
				{
					Log.Error("TemplateDocument", ex);
				}
				text2 = text;
			}
			else
			{
				text2 = templateDocument.PageHtml();
			}
			return text2;
		}

		// Token: 0x06000196 RID: 406 RVA: 0x0000B128 File Offset: 0x00009328
		public string PageHtml()
		{
			return this.PageHtml(this.FilePath);
		}

		// Token: 0x06000197 RID: 407 RVA: 0x0000B148 File Offset: 0x00009348
		public string PageHtml(string file)
		{
			string text = File.ReadAllText(this.TemplateBank.Path.Physics + file, Encoding.UTF8);
			text = this.Meta(text);
			text = TemplateDocument.TransformPath(text, this.AbsolutePath, this.TemplateBank.Path.Virtual + this.FilePath);
			List<TemplateDocument.TagInclude> list = TemplateDocument.TagInclude.GetInclude(text, this.Type);
			while (list.Count > 0)
			{
				foreach (TemplateDocument.TagInclude tagInclude in list)
				{
					this.AddFileDependency(tagInclude.FileHyPath);
					text = tagInclude.Transform(text, this.AbsolutePath);
				}
				list = TemplateDocument.TagInclude.GetInclude(text, this.Type);
			}
			bool isTrim = Template.IsTrim;
			if (isTrim)
			{
				text = Regex.Replace(text, "(<!--).*(-->)", "", RegexOptions.Multiline);
				text = Regex.Replace(text, "//([^\"\\r\\n]*)[\\r\\n]", "", RegexOptions.Multiline);
				text = Regex.Replace(text, "(\\/\\*(\\n|.)*?\\*\\/)", "", RegexOptions.Multiline);
				text = Regex.Replace(text, "\\s{2,}", " ", RegexOptions.Singleline);
				text = Regex.Replace(text, "(?<=\\>)\\s+(?=\\<)|(?<=\\>)\\s+(?=\\S)|(?<=\\S)\\s+(?=\\<)", "", RegexOptions.Singleline);
				text = Regex.Replace(text, "(<!--).*(-->)", "", RegexOptions.Singleline);
			}
			return text;
		}

		// Token: 0x06000198 RID: 408 RVA: 0x0000B2B0 File Offset: 0x000094B0
		public string Meta(string html)
		{
			TemplateBank templateBank = this.TemplateBank;
			StringBuilder stringBuilder = new StringBuilder();
			License value = License.Value;
			string text = Copyright.Value("powerby");
			bool flag = Server.IsLocalIP || Server.IsIntranetIP;
			bool flag2 = !flag;
			if (flag2)
			{
				text = ((string.IsNullOrWhiteSpace(text) || !value.IsLicense) ? "www.weishakeji.net" : text);
			}
			string text2 = "<meta powerby=\"{0}\" license=\"{1}\" build-number=\"{2}\"/>";
			stringBuilder.Append("\r\n" + string.Format(text2, text, value.IsLicense.ToString().ToLower(), Request.Version));
			stringBuilder.Append(string.Format("\r\n<meta device=\"{1}\" template=\"{0}\" cache=\"{3}\" path=\"{2}\"/>", new object[]
			{
				templateBank.Name.ToLower(),
				this.Type.ToLower(),
				templateBank.Path.Virtual.ToLower(),
				Template.IsCache.ToString().ToLower()
			}));
			string text3 = templateBank.Path.Virtual + this.FilePath;
			string text4 = string.Format("/{0}/", this.Type);
			text4 += (string.IsNullOrEmpty(this.Module) ? this.FileView : string.Format("{0}/{1}", this.Module, this.FileView));
			stringBuilder.Append(string.Format("\r\n<meta view=\"{0}\" route=\"{1}\" page=\"{2}\"/>", this.FileName, text4.ToLower(), text3.ToLower()));
			html = Regex.Replace(html, "(<head [^>]*>)|(<head>)", "$0 " + stringBuilder.ToString(), RegexOptions.IgnoreCase);
			bool flag3 = templateBank.OrganInfo != null;
			if (flag3)
			{
				bool flag4 = !string.IsNullOrEmpty(templateBank.OrganInfo.Org_ExtraWeb) && templateBank.Virtual.ToLower().IndexOf("/templates/web") > -1;
				if (flag4)
				{
					html = Regex.Replace(html, "(</body>)", "<!--附加代码-->" + templateBank.OrganInfo.Org_ExtraWeb + "$0", RegexOptions.IgnoreCase);
				}
				bool flag5 = !string.IsNullOrEmpty(templateBank.OrganInfo.Org_ExtraMobi) && templateBank.Virtual.ToLower().IndexOf("/templates/mobi") > -1;
				if (flag5)
				{
					html = Regex.Replace(html, "(</body>)", "<!--附加代码-->" + templateBank.OrganInfo.Org_ExtraMobi + "$0", RegexOptions.IgnoreCase);
				}
			}
			return html;
		}

		// Token: 0x06000199 RID: 409 RVA: 0x0000B51C File Offset: 0x0000971C
		public static string TransformPath(string text, string page, string tmFile)
		{
			return TemplateDocument.TransformPath(text, page, tmFile, "html|body|link|script|img|iframe|include");
		}

		// Token: 0x0600019A RID: 410 RVA: 0x0000B53C File Offset: 0x0000973C
		public static string TransformPath(string text, string page, string tmFile, string tags)
		{
			string text2 = tmFile.Substring(0, tmFile.LastIndexOf("/") + 1);
			RegexOptions regexOptions = RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace;
			string text3 = "<(" + tags + ")[^>]+>";
			foreach (object obj in new Regex(text3, regexOptions).Matches(text))
			{
				Match match = (Match)obj;
				string text4 = match.Groups[1].Value.Trim();
				string text5 = match.Groups[0].Value.Trim();
				string text6 = "(?<=\\s+)(?<key>path|href|file|src|error|default|action|background[^=\"']*)=([\"'])?(?<value>[^'\">]*)\\1?";
				foreach (object obj2 in new Regex(text6, regexOptions).Matches(text5))
				{
					Match match2 = (Match)obj2;
					string text7 = match2.Groups["key"].Value.Trim();
					string text8 = match2.Groups["value"].Value.Trim();
					bool flag = new Regex("^data:image").IsMatch(text8);
					if (!flag)
					{
						bool flag2 = (text7.ToLower() == "error" || text7.ToLower() == "default") && text4.ToLower() != "img";
						if (!flag2)
						{
							bool flag3 = new Regex("^javascript:").IsMatch(text8);
							if (!flag3)
							{
								bool flag4 = new Regex("[a-zA-z]+://[^\\s]*", RegexOptions.Singleline).IsMatch(text8);
								if (!flag4)
								{
									bool flag5 = new Regex("^[{\\#]").IsMatch(text8);
									if (!flag5)
									{
										text8 = TemplateDocument.RelativePath(text2, text8);
										text8 = TemplateDocument.TransformPath_Version(text8);
										text8 = match2.Groups[2].Value + "=\"" + text8 + "\"";
										text8 = Regex.Replace(text8, "//", "/");
										text5 = text5.Replace(match2.Value, text8);
									}
								}
							}
						}
					}
				}
				text = text.Replace(match.Groups[0].Value.Trim(), text5);
			}
			return text;
		}

		// Token: 0x0600019B RID: 411 RVA: 0x0000B7EC File Offset: 0x000099EC
		public static string TransformPath_Version(string url)
		{
			bool flag = url.IndexOf("?") > 0;
			string text;
			if (flag)
			{
				text = url + "&version=" + PlateOrganInfo.Version;
			}
			else
			{
				bool flag2 = url.IndexOf("?") < 0;
				if (flag2)
				{
					text = url + "?version=" + PlateOrganInfo.Version;
				}
				else
				{
					text = url;
				}
			}
			return text;
		}

		// Token: 0x0600019C RID: 412 RVA: 0x0000B84C File Offset: 0x00009A4C
		public static string RelativePath(string baseFile, string targetFile)
		{
			baseFile = baseFile.Replace("\\", "/").ToLower();
			targetFile = targetFile.Replace("\\", "/").ToLower();
			bool flag = targetFile.Length > 0 && targetFile.Substring(0, 1) == "/";
			string text;
			if (flag)
			{
				text = targetFile;
			}
			else
			{
				while (baseFile.IndexOf("/") > -1 && targetFile.IndexOf("/") > -1)
				{
					string text2 = baseFile.Substring(0, baseFile.IndexOf("/"));
					string text3 = targetFile.Substring(0, targetFile.IndexOf("/"));
					bool flag2 = text2 != text3;
					if (flag2)
					{
						break;
					}
					baseFile = baseFile.Substring(baseFile.IndexOf("/") + 1);
					targetFile = targetFile.Substring(targetFile.IndexOf("/") + 1);
				}
				List<string> list = baseFile.Split(new char[] { '/' }).ToList<string>();
				for (int i = 0; i < list.Count; i++)
				{
					bool flag3 = list[i] == "";
					if (flag3)
					{
						list.RemoveAt(i);
						i--;
					}
				}
				List<string> list2 = targetFile.Split(new char[] { '/' }).ToList<string>();
				int num = ((list.Count < list2.Count) ? list.Count : list2.Count);
				for (int j = 0; j < ((list.Count < list2.Count) ? list.Count : list2.Count); j++)
				{
					bool flag4 = list.Count < 1;
					if (flag4)
					{
						break;
					}
					bool flag5 = list2[j] == "..";
					if (flag5)
					{
						list.RemoveAt(list.Count - 1);
						list2.RemoveAt(j);
						j--;
					}
				}
				string text4 = string.Empty;
				foreach (string text5 in list)
				{
					text4 = text4 + "/" + text5;
				}
				foreach (string text6 in list2)
				{
					text4 = text4 + "/" + text6;
				}
				text4 = TemplateDocument.RelativePath_ClearnPoint(text4);
				text = text4;
			}
			return text;
		}

		// Token: 0x0600019D RID: 413 RVA: 0x0000BAF8 File Offset: 0x00009CF8
		public static string RelativePath_ClearnPoint(string path)
		{
			bool flag = path.IndexOf("/") < 0;
			string text;
			if (flag)
			{
				text = path;
			}
			else
			{
				bool flag2 = path.IndexOf("../") < 0;
				if (flag2)
				{
					text = path;
				}
				else
				{
					Stack stack = new Stack();
					string[] array = path.Split(new char[] { '/' });
					string text2 = "";
					int num = 0;
					while (array[num] == "..")
					{
						text2 = text2 + array[num++] + "/";
					}
					int i = num;
					while (i < array.Length)
					{
						bool flag3 = array[i] == "..";
						if (!flag3)
						{
							goto IL_00C5;
						}
						bool flag4 = i > 0 && array[i - 1] != "..";
						if (!flag4)
						{
							goto IL_00C5;
						}
						stack.Pop();
						IL_00D1:
						i++;
						continue;
						IL_00C5:
						stack.Push(array[i]);
						goto IL_00D1;
					}
					string text3 = "";
					foreach (object obj in stack)
					{
						string text4 = (string)obj;
						text3 = text4 + "/" + text3;
					}
					bool flag5 = text3.Length > 0;
					if (flag5)
					{
						string text5 = text3.Substring(text3.Length - 1);
						bool flag6 = text5 == "/";
						if (flag6)
						{
							text3 = text3.Substring(0, text3.Length - 1);
						}
					}
					bool flag7 = text3.IndexOf("../") > -1;
					if (flag7)
					{
						text3 = TemplateDocument.RelativePath_ClearnPoint(text3);
					}
					text = text2 + text3;
				}
			}
			return text;
		}

		// Token: 0x04000074 RID: 116
		protected List<string> _fileDependencies = null;

		// Token: 0x04000075 RID: 117
		private static readonly object _fileDependencies_lock = new object();

		// Token: 0x04000077 RID: 119
		private static object _lock_cache = new object();

		// Token: 0x02000049 RID: 73
		public class TagInclude
		{
			// Token: 0x1700010C RID: 268
			// (get) Token: 0x060002DC RID: 732 RVA: 0x00013918 File Offset: 0x00011B18
			// (set) Token: 0x060002DD RID: 733 RVA: 0x00013920 File Offset: 0x00011B20
			public string Element { get; set; }

			// Token: 0x1700010D RID: 269
			// (get) Token: 0x060002DE RID: 734 RVA: 0x00013929 File Offset: 0x00011B29
			// (set) Token: 0x060002DF RID: 735 RVA: 0x00013931 File Offset: 0x00011B31
			public string FileAttr { get; set; }

			// Token: 0x1700010E RID: 270
			// (get) Token: 0x060002E0 RID: 736 RVA: 0x0001393A File Offset: 0x00011B3A
			// (set) Token: 0x060002E1 RID: 737 RVA: 0x00013942 File Offset: 0x00011B42
			public string FromAttr { get; set; }

			// Token: 0x1700010F RID: 271
			// (get) Token: 0x060002E2 RID: 738 RVA: 0x0001394B File Offset: 0x00011B4B
			// (set) Token: 0x060002E3 RID: 739 RVA: 0x00013953 File Offset: 0x00011B53
			public string FileVirPath { get; set; }

			// Token: 0x17000110 RID: 272
			// (get) Token: 0x060002E4 RID: 740 RVA: 0x0001395C File Offset: 0x00011B5C
			// (set) Token: 0x060002E5 RID: 741 RVA: 0x00013964 File Offset: 0x00011B64
			public string FileHyPath { get; set; }

			// Token: 0x17000111 RID: 273
			// (get) Token: 0x060002E6 RID: 742 RVA: 0x0001396D File Offset: 0x00011B6D
			// (set) Token: 0x060002E7 RID: 743 RVA: 0x00013975 File Offset: 0x00011B75
			public TemplateBank TemplateBank { get; set; }

			// Token: 0x060002E8 RID: 744 RVA: 0x00013980 File Offset: 0x00011B80
			public string Transform(string html, string baseurl)
			{
				string text = string.Empty;
				string text2 = Server.MapPath(this.FileVirPath);
				bool flag = File.Exists(text2);
				if (flag)
				{
					text = File.ReadAllText(text2, Encoding.UTF8);
				}
				text = TemplateDocument.TransformPath(text, baseurl, this.FileVirPath);
				return html.Replace(this.Element, text);
			}

			// Token: 0x060002E9 RID: 745 RVA: 0x000139D8 File Offset: 0x00011BD8
			public static List<TemplateDocument.TagInclude> GetInclude(string html, string tmType)
			{
				TemplateConfingItem templateConfingItem = Template.ForAny(tmType);
				TemplateBank templateBank = templateConfingItem.Current;
				List<TemplateDocument.TagInclude> list = new List<TemplateDocument.TagInclude>();
				RegexOptions regexOptions = RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace;
				foreach (object obj in new Regex(TemplateDocument.TagInclude.RegexTagExpr, regexOptions).Matches(html))
				{
					Match match = (Match)obj;
					TemplateDocument.TagInclude tagInclude = new TemplateDocument.TagInclude();
					tagInclude.Element = match.Groups[0].Value.Trim();
					foreach (object obj2 in new Regex(TemplateDocument.TagInclude.RegexAttrExpr, regexOptions).Matches(tagInclude.Element))
					{
						Match match2 = (Match)obj2;
						string text = match2.Groups["key"].Value.Trim();
						string text2 = match2.Groups["value"].Value.Trim();
						bool flag = string.IsNullOrWhiteSpace(text2);
						if (!flag)
						{
							bool flag2 = text2.IndexOf("?") > -1;
							if (flag2)
							{
								text2 = text2.Substring(0, text2.LastIndexOf("?"));
							}
							bool flag3 = "file".Equals(text, StringComparison.CurrentCultureIgnoreCase);
							if (flag3)
							{
								tagInclude.FileAttr = text2;
							}
							bool flag4 = "from".Equals(text, StringComparison.CurrentCultureIgnoreCase);
							if (flag4)
							{
								tagInclude.FromAttr = text2;
							}
						}
					}
					tagInclude.TemplateBank = (string.IsNullOrWhiteSpace(tagInclude.FromAttr) ? templateBank : templateConfingItem.GetTemplate(tagInclude.FromAttr));
					bool flag5 = tagInclude.TemplateBank == null;
					if (flag5)
					{
						tagInclude.TemplateBank = templateBank;
					}
					tagInclude.FileVirPath = tagInclude.FileAttr;
					tagInclude.FileHyPath = Server.MapPath(tagInclude.FileVirPath);
					list.Add(tagInclude);
				}
				return list;
			}

			// Token: 0x040000E6 RID: 230
			private static string RegexTagExpr = "<include[^>]+/>";

			// Token: 0x040000E7 RID: 231
			private static string RegexAttrExpr = "(?<=\\s+)(?<key>file|from[^=\"']*)=([\"'])?(?<value>[^'\">]*)\\1?";
		}
	}
}
